package net1;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UdpServer {
    private static final int port = 8888;

    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(port);

        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
            System.out.println("-------------------------------------------");
            System.out.println("等待接收udp数据报...");
            socket.receive(packet);
            System.out.println("客户端ip: " + packet.getAddress().getHostAddress());
            System.out.println("客户端port: " + packet.getPort());
            System.out.println("客户端发送的数据为： " + new String(packet.getData()).substring(0,17));
        }
    }
}
